Skip to content

feat: Add Cloudflare Workers observability and logging#9

Merged
paveg merged 1 commit intomainfrom
feat/cloudflare-observability
Jan 2, 2026
Merged

feat: Add Cloudflare Workers observability and logging#9
paveg merged 1 commit intomainfrom
feat/cloudflare-observability

Conversation

@paveg
Copy link
Owner

@paveg paveg commented Jan 2, 2026

Summary

  • Enable Cloudflare Workers Logs with full request sampling in wrangler.toml
  • Add Analytics Engine integration (devcard_metrics dataset) for metrics collection
  • Create new observability.ts utility with structured logging and W3C Trace Context support
  • Enhance logger middleware to record metrics and add trace headers to responses
  • Add GitHub API monitoring with rate limit tracking and warnings

Changes

wrangler.toml

  • Add [observability] section with logs enabled
  • Add [[analytics_engine_datasets]] for metrics storage
  • Add LOG_LEVEL environment variable
  • Add nodejs_compat compatibility flag

New File: src/utils/observability.ts

  • Logger class with structured JSON logging (debug/info/warn/error levels)
  • Observability class for Analytics Engine integration
  • Request, error, cache, and GitHub API metrics recording
  • W3C Trace Context utilities (traceId/spanId generation)

Enhanced: src/middleware/logger.ts

  • W3C Trace Context support (traceparent header parsing)
  • Response headers: X-Trace-Id, X-Span-Id, X-Ray-Id
  • Automatic log level based on status code (4xx=warn, 5xx=error)
  • Analytics Engine integration for request metrics

Enhanced: src/fetchers/github.ts

  • API call timing and metrics recording
  • Rate limit monitoring with warnings when remaining < 100
  • Endpoint-specific tracking (user_stats, top_languages, repo_info)

Test plan

  • Run pnpm typecheck - passes
  • Run pnpm build - passes
  • Run npx wrangler deploy --dry-run - shows correct bindings
  • Deploy to Cloudflare and verify logs appear in dashboard
  • Verify Analytics Engine dataset receives metrics

🤖 Generated with Claude Code

- Enable Workers Logs in wrangler.toml with full sampling
- Add Analytics Engine integration for metrics collection
- Create observability utility module with structured logging
- Enhance logger middleware with W3C Trace Context support
- Add GitHub API monitoring with rate limit tracking
- Update Monitor class with Analytics Engine integration
- Add trace headers (X-Trace-Id, X-Span-Id, X-Ray-Id) to responses

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@paveg paveg merged commit f2e0260 into main Jan 2, 2026
4 checks passed
@paveg paveg deleted the feat/cloudflare-observability branch January 2, 2026 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant